package com.school.service.impl;

import com.school.dao.RoleMapper;
import com.school.model.Role;
import com.school.model.RoleExample;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RoleServiceImpl {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private RoleMapper roleMapper;

    public Role queryById(Integer id) {
        RoleExample roleExample = new RoleExample();
        RoleExample.Criteria criteria = roleExample.createCriteria();

        criteria.andIdEqualTo(id);
        criteria.andDeletedEqualTo((byte) 0);

        List<Role> roles = roleMapper.selectByExampleSelective(roleExample);
        return roles.size() == 0 ? null : roles.get(0);
    }

    public Role queryByName(String name) {
        RoleExample roleExample = new RoleExample();
        RoleExample.Criteria criteria = roleExample.createCriteria();

        criteria.andNameEqualTo(name);
        criteria.andDeletedEqualTo((byte) 0);

        List<Role> roles = roleMapper.selectByExampleSelective(roleExample);
        return roles.size() == 0 ? null : roles.get(0);

    }
}
